package L618;

import util.TreeNode;

import java.util.Stack;

/**
 * @program: javase
 * @description: 判断二叉树是否为二叉排序树
 * @author: luolidong
 * @create: 2021-06-18 22:25
 * @version: 1.0
 */
public class JudgeSortTree {
    public boolean isValidBST(TreeNode root) {
        if (root == null) return false;
        Stack<TreeNode> stack = new Stack<>();
        double preVal = Double.MIN_VALUE;
        while (!stack.isEmpty() || root != null) {
            if (root != null) {
                stack.push(root);
                root = root.left;
            } else {
                root = stack.pop();
                if (root.val <= preVal) return false;
                preVal = root.val;
                root = root.right;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(Double.MAX_VALUE);
        System.out.println(Double.MIN_VALUE);
    }
}
